<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../css/mui.min.css">
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			.mui-loader {
				position: absolute;
				top: 25%;
				width: 100%;
				height: 60%;
				color: #888;
				font-size: 14px;
				text-align: center;
			}
			.mui-fadein {
				opacity: 1;
			}
			.mui-fadeout {
				opacity: 0;
			}
			@keyframes fadein {
				from {
					opacity: 0;
				}
				to {
					opacity: 1;
				}
			}
			@-webkit-keyframes fadein {
				from {
					opacity: 0;
				}
				to {
					opacity: 1;
				}
			}
			@keyframes fadeout {
				from {
					opacity: 1;
				}
				to {
					opacity: 0;
				}
			}
			@-webkit-keyframes fadeout {
				from {
					opacity: 1;
				}
				to {
					opacity: 0;
				}
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a id="back" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<a id="menu" class="mui-action-menu mui-icon mui-icon-bars mui-pull-right" style="display: none;"></a>
			<h1 id="title" class="mui-title"></h1>
		</header>
		<div class="mui-loader">加载中...</div>
	</body>
	<script src="../js/mui.min.js"></script>
	<script type="text/javascript">
		//启用双击监听
		mui.init({
			gestureConfig:{
				doubletap:true
			}
		});
		var contentWebview = null,self = null;
		mui.plusReady(function () {
			self = plus.webview.currentWebview();
		});
		mui.back = function() {
			self.hide('auto');
			setTimeout(function() {
				titleElem.className = 'mui-title mui-fadeout';
				titleElem.innerText = '';
				if(contentWebview==null){
					contentWebview = self.children()[0];
				}
				contentWebview.hide("none");
			}, 350);
		}
		
		var titleElem = document.getElementById("title")
		var menuElem = document.getElementById("menu")

		window.addEventListener("updateHeader", function(e) {
			var title = e.detail.title;
			var showMenu = e.detail.showMenu;
			var href = e.detail.target;
			var aniShow = e.detail.aniShow;
			titleElem.innerHTML = title;
			titleElem.className = "mui-title mui-fadein";
			var display = showMenu ? "" : "none";
			if (showMenu) {
				mui.options.keyEventBind.menubutton = true;
			} else {
				mui.options.keyEventBind.menubutton = false;
			}
			menu.style.display = display;
			
			if(mui.os.android&&aniShow&&parseFloat(mui.os.version)>=4.4){
				if(contentWebview==null){
					contentWebview = self.children()[0];
				}
				
				if (contentWebview.getURL() != href) {
					contentWebview.loadURL(href);
				} else {
					contentWebview.show();
				}
				setTimeout(function () {
					self.show(aniShow);
				},10);
			}
		});
		
		
		menuElem.addEventListener('tap', function(e) {
			e.stopPropagation();
			if(contentWebview==null){
				contentWebview = plus.webview.currentWebview().children()[0];
			}
			contentWebview.evalJS('mui("#topPopover").popover("toggle")');
		});
		document.querySelector('header').addEventListener('doubletap',function () {
			if(contentWebview==null){
				contentWebview = plus.webview.currentWebview().children()[0];
			}
			contentWebview.evalJS('mui.scrollTo(0, 100)');
		});
		
		mui.menu = function () {
			console.log(menuElem.style.display);
			if(menuElem.style.display !== "none"){
				if(contentWebview==null){
					contentWebview = plus.webview.currentWebview().children()[0];
				}
				contentWebview.evalJS('mui("#topPopover").popover("toggle")');
			}
		}
	</script>

</html>